import json
import pyautogui
import time
import pandas as pd

# 读入json文件的参数
with open(r"./config - 不改朝向.json", "r", encoding="utf-8") as f:
    content = json.load(f)
    Clicks_counts = content['Clicks_counts']
    Coordinate_array1 = content['Coordinate_array1']
    Coordinate_array2 = content['Coordinate_array2']
    Coordinate_array3 = content['Coordinate_array3']
    #
    double_click_Coordinate_array = content['double_click_Coordinate_array']
    #
    Time_list1 = content['Time_list1']
    Time_list2 = content['Time_list2']
    Time_list3 = content['Time_list3']
    #
    #Type_data = content['Type_data']
    #Type_interval = content['Type_interval']

address = pd.read_excel(r'浙江经纬度.xlsx')
print(address.head(5))


count = 0
while count < Clicks_counts:
    length1 = Coordinate_array1.__len__()  # 获得长度
    for i in range(length1):
        pyautogui.click(Coordinate_array1[i][0], Coordinate_array1[i][1])  # 每次需要点击的地方
        time.sleep(Time_list1[i])  # 每次需要等待的时间

    #双击,输入经纬度
    pyautogui.doubleClick(double_click_Coordinate_array[0][0],double_click_Coordinate_array[0][1])
    time.sleep(0.2)
    pyautogui.typewrite(str(address.iloc[count]['lat']))
    time.sleep(0.2)
    pyautogui.doubleClick(double_click_Coordinate_array[1][0], double_click_Coordinate_array[1][1])
    time.sleep(0.2)
    pyautogui.typewrite(str(address.iloc[count]['lon']))
    time.sleep(0.2)

    length2 = Coordinate_array2.__len__()  # 获得长度
    for i in range(length2):
        pyautogui.click(Coordinate_array2[i][0], Coordinate_array2[i][1])  # 每次需要点击的地方
        time.sleep(Time_list2[i])

    #输入文件名称保存9
    pyautogui.typewrite(str(address.iloc[count]['百度地图经纬度']))

    length3 = Coordinate_array3.__len__()  # 获得长度
    for i in range(length3):
        pyautogui.click(Coordinate_array3[i][0], Coordinate_array3[i][1])  # 每次需要点击的地方
        time.sleep(Time_list3[i])

    count += 1